<% if current_user %>
<h1>Open Orders</h1>

<table cellspacing="10">
  <tr>
    <th>Restaurant</th>
    <th>Bounty</th>
    <th>Cost</th>
    <th>Destination</th>
    <th>Content</th>
    <th>Customer</th>
    <th></th>
    <th></th>
    <th></th>
  </tr>

<% @orders.each do |order| %>
  <tr>
    <td><%= order.restaurant %></td>
    <td><%= number_to_currency(order.bounty) %></td>
    <td><%= number_to_currency(order.order_cost) %></td>
    <td><%= order.order_destination %></td>
    <td><%= order.content %></td>
    <td><%= User.find(order.user_id).email %></td>
    <td><%= link_to 'Show', order %></td>
    <% if order.user_id = current_user.id && !order.driver_id && !(order.delivery_failed || order.delivery_completed) || current_user.isadmin%>
    <td><%= link_to 'Edit', edit_order_path(order) %></td>
    <td><%= link_to 'Destroy', order, :confirm => 'Are you sure?', :method => :delete %></td>
    <% else %>
    <td></td>
    <td></td>
    <% end %>
  </tr>
<% end %>
</table>

<br />

<% if current_user.iscustomer %>
<%= link_to 'Place an Order', new_order_path %>
<% end %>
<%= link_to 'Back', :back %>
<% else %>
<p>Error: You are not currently logged in.</p>
<p>If you would like to view active orders, please <%= link_to "log in", log_in_path %>.<p>
<p>If you do not have an account, please <%= link_to "sign up", sign_up_path %><p>
<p>Or you can return to the <%= link_to "home page", root_url %>.<p>
<% end %>
